package com.union.dao;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.union.entitybean.Personinfo;

/**
 	* A data access object (DAO) providing persistence and search support for Personinfo entities.
 			* Transaction control of the save(), update() and delete() operations 
		can directly support Spring container-managed transactions or they can be augmented	to handle user-managed Spring transactions. 
		Each of these methods provides additional information for how to configure it for the desired type of transaction control. 	
	 * @see com.union.entitybean.Personinfo
  * @author MyEclipse Persistence Tools 
 */

public class PersoninfoDAO extends HibernateDaoSupport {
	private static final Log log = LogFactory.getLog(PersoninfoDAO.class);
	//property constants
	public static final String MEMBERSHIP = "membership";
	public static final String AFFILIATION = "affiliation";
	public static final String EXT = "ext";
	public static final String TEL = "tel";
	public static final String TEL2 = "tel2";
	public static final String TEL_NIGHT = "telNight";
	public static final String MOBILE = "mobile";
	public static final String FAX = "fax";
	public static final String ADD1 = "add1";
	public static final String ADD2 = "add2";
	public static final String ADD3 = "add3";
	public static final String EMAIL = "email";
	public static final String EMAIL2 = "email2";
	public static final String SUPPORTER = "supporter";
	public static final String VOLUNTEER = "volunteer";
	public static final String KEPT_INFORMED = "keptInformed";

	protected void initDao() {
		//do nothing
	}

	public void save(Personinfo transientInstance) {
		log.debug("saving Personinfo instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Personinfo persistentInstance) {
		log.debug("deleting Personinfo instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Personinfo findById(java.lang.Integer id) {
		log.debug("getting Personinfo instance with id: " + id);
		try {
			Personinfo instance = (Personinfo) getHibernateTemplate().get(
					"com.test.Personinfo", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Personinfo instance) {
		log.debug("finding Personinfo instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Personinfo instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Personinfo as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByMembership(Object membership) {
		return findByProperty(MEMBERSHIP, membership);
	}

	public List findByAffiliation(Object affiliation) {
		return findByProperty(AFFILIATION, affiliation);
	}

	public List findByExt(Object ext) {
		return findByProperty(EXT, ext);
	}

	public List findByTel(Object tel) {
		return findByProperty(TEL, tel);
	}

	public List findByTel2(Object tel2) {
		return findByProperty(TEL2, tel2);
	}

	public List findByTelNight(Object telNight) {
		return findByProperty(TEL_NIGHT, telNight);
	}

	public List findByMobile(Object mobile) {
		return findByProperty(MOBILE, mobile);
	}

	public List findByFax(Object fax) {
		return findByProperty(FAX, fax);
	}

	public List findByAdd1(Object add1) {
		return findByProperty(ADD1, add1);
	}

	public List findByAdd2(Object add2) {
		return findByProperty(ADD2, add2);
	}

	public List findByAdd3(Object add3) {
		return findByProperty(ADD3, add3);
	}

	public List findByEmail(Object email) {
		return findByProperty(EMAIL, email);
	}

	public List findByEmail2(Object email2) {
		return findByProperty(EMAIL2, email2);
	}

	public List findBySupporter(Object supporter) {
		return findByProperty(SUPPORTER, supporter);
	}

	public List findByVolunteer(Object volunteer) {
		return findByProperty(VOLUNTEER, volunteer);
	}

	public List findByKeptInformed(Object keptInformed) {
		return findByProperty(KEPT_INFORMED, keptInformed);
	}

	public List findAll() {
		log.debug("finding all Personinfo instances");
		try {
			String queryString = "from Personinfo";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Personinfo merge(Personinfo detachedInstance) {
		log.debug("merging Personinfo instance");
		try {
			Personinfo result = (Personinfo) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Personinfo instance) {
		log.debug("attaching dirty Personinfo instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Personinfo instance) {
		log.debug("attaching clean Personinfo instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static PersoninfoDAO getFromApplicationContext(ApplicationContext ctx) {
		return (PersoninfoDAO) ctx.getBean("PersoninfoDAO");
	}
}